//
//  BuyViewController.m
//  礼物说
//
//  Created by dllo on 16/4/25.
//  Copyright © 2016年 sunzhichao. All rights reserved.
//

#import "BuyViewController.h"

@interface BuyViewController ()<UIWebViewDelegate>

@property (nonatomic, retain) UIWebView *webView;

@end

@implementation BuyViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}
- (void)dealloc {
    [_webView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, kWIDTH, kHEIGHT)];
    [self.view addSubview:_webView];
    [_webView release];
    
    _webView.delegate = self;
    
    NSURL *url = [NSURL URLWithString:@"https://www.taobao.com"];
    [_webView loadRequest:[NSURLRequest requestWithURL:url]];
    
    [self setBarButton];
}

#pragma mark - 设置导航栏按钮（一会做演示，返回，前进，刷新）
- (void)setBarButton {
    UIBarButtonItem *fanhui = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(fanHui:)];
    UIBarButtonItem *left1 = [[UIBarButtonItem alloc] initWithTitle:@"后退" style:UIBarButtonItemStylePlain target:self action:@selector(houtui:)];
    UIBarButtonItem *left2 = [[UIBarButtonItem alloc] initWithTitle:@"前进" style:UIBarButtonItemStylePlain target:self action:@selector(QianJin:)];
    
    self.navigationItem.leftBarButtonItems = @[fanhui,left1,left2];
    [left1 release];
    [left2 release];
    [fanhui release];
    
    UIBarButtonItem *right = [[UIBarButtonItem alloc] initWithTitle:@"刷新" style:UIBarButtonItemStylePlain target:self action:@selector(rightAction:)];
    self.navigationItem.rightBarButtonItem = right;
    [right release];
}

- (void)fanHui:(UIBarButtonItem *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark  按钮事件
//返回
- (void)houtui:(UIBarButtonItem *)sender
{
    [self.webView goBack]; //返回
}
//前进
- (void)QianJin:(UIBarButtonItem *)sender
{
    [self.webView goForward]; //前进
}
//刷新
- (void)rightAction:(UIBarButtonItem *)sender
{
    
    [self.webView reload];//从新加载数据
}

#pragma mark 代理方法
//- (void)webView:(UIWebView *)webView didStartProvisionalNavigation:( *)navigation{
//    
//    NSLog(@"开始加载%s--%d",__FUNCTION__,__LINE__);
//    [GiFHUD show];
//    
//}
//- (void)webView:(UIWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
//    
//    NSLog(@"完成加载%s--%d",__FUNCTION__,__LINE__);
//    [GiFHUD dismiss];
//    
//}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
